/*jslint newcap:true, browser: true, devel: true, bitwise: true, white: true, plusplus: true */
/*global define:true */

/**
 * @module Core
 */

define(['WID/Core/Class','WID/Core/BlankLoadingScreen'],function(Class,BlankLoadingScreen) {
"use strict";

/** 
 * @class SubViews
 * @constructor
 */
var SubViews = function(parentView, subViewsNames) {
	this.ParentView = parentView;
	this.Subs = subViewsNames;
	
	var 
		context = this,
		current = 0,
		length = subViewsNames.length; 
	this.onSubLoaded = function(subView) {
		var sub = new subView(parentView);
		context.Subs[current++] = sub;
		sub.init(function() {
			if (current < length) {
				context.load(current);
			} else {
				context.ParentView.onSubsLoaded.call(context.ParentView);
			}
		});
	};
};

return Class(SubViews,{methods: {
	constructor: SubViews,
	
	load: function(index) {
		var subName = this.Subs[index||0];
		require([this.ParentView.SubsPath+subName],this.onSubLoaded);
	},
	
	dispose: function() {
		var i = this.Subs.lenght;
		while (i--) {
			this.Subs[i].dispose();
		}
	}
}});

});
